package com.opesoft.calendar.action;

import java.util.List;

import javax.servlet.http.Cookie;

import org.apache.log4j.Logger;

import com.opesoft.calendar.biz.DateUtils;
import com.opesoft.calendar.biz.Month;
import com.opesoft.calendar.biz.NoteBO;
import com.opesoft.calendar.biz.NoteTypeBO;
import com.opesoft.calendar.model.NoteType;
import com.opesoft.fw.ajax.Ajax;
import com.opesoft.fw.ajax.AjaxWebManager;

public class CalendarAction
{
	Logger log=Logger.getLogger(this.getClass());

	@Ajax(clientCall=true)
	public int[][] nowMonth()
	{
		Month m=new Month();
		return m.matrixDays();
	}

	@Ajax(clientCall=true)
	public int[][] month(int year,int month)
	{
		Month m=new Month(year,month);
		return m.matrixDays();
	}

	@Ajax(clientCall=true)
	public String[][] notesInDay(int year,int month,int day)
	{
		Cookie[] cookies=AjaxWebManager.request().getCookies();
		if(cookies!=null)
		{
			for(int i=0;i<cookies.length;i++)
			{
				Cookie cookie=cookies[i];
				log.debug("Cookie : "+cookie.getName()+" -> "+cookie.getValue());
			}
		}

		NoteBO bo=new NoteBO();
		return bo.searchInDay(year,month,day,DateUtils.getNoteTypesFromCookie());
	}

	@Ajax(clientCall=true)
	public String[][] noteTypes()
	{
		NoteTypeBO bo=new NoteTypeBO();
		return bo.searchNoteTypes();
	}

	@Ajax(clientCall=true)
	public NoteType noteType(long id)
	{
		NoteTypeBO bo=new NoteTypeBO();
		return bo.findNoteType(id);
	}

	@Ajax(clientCall=true)
	public List<Object> getNote(long id)
	{
		NoteBO bo=new NoteBO();
		return bo.search(id);
	}
}
